<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../static/css/typo.css">
    <link rel="stylesheet" href="../static/css/animate.css">
    <link rel="stylesheet" href="../static/lib/prism/prism.css">
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
    <link rel="stylesheet" href="../static/css/me.css">
</head>
<body>
<!-- 导航-->
    <nav th:replace="_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
        <div class="ui container">
            <div class="ui inverted secondary stackable menu">
                <h2 class="ui header teal item">Blog</h2>
                <a href="#" class="m-item item m-mobile-hide"><i class="home icon"></i>首页</a>
                <a href="#" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
                <a href="#" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
                <a href="#" class="m-item item m-mobile-hide"><i class="clone icon"></i>归档</a>
                <a href="#" class="m-item item m-mobile-hide"><i class="info icon"></i>关于我</a>
                <div class="right m-item item m-mobile-hide">
                    <div class="ui icon inverted transparent input">
                        <input type="text" placeholder="Search...">
                        <i class="search link icon"></i>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>

<!--中间内容-->
    <div class="m-container m-padded-tb-big animated fadeIn">
        <!--header-->
        <div class="ui container">
            <div class="ui top attached segment">
                <div class="ui horizontal link list">
                    <div class="item">
                        <img src="https://picsum.photos/id/10/100/100" th:src="@{${blog.user.avatar}}" alt="" class="ui avatar image">
                        <div class="content"><a href="#" class="header" th:text="${blog.user.nickname}">Su</a></div>
                    </div>
                    <div class="item">
                        <i class="calendar icon"></i><span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2021-3-1</span>
                    </div>
                    <div class="item">
                        <i class="eye icon"></i><span th:text="${blog.views}">233</span>
                    </div>
                </div>
            </div>

            <!--image-->
            <div class="ui attached segment">
                <img src="https://picsum.photos/seed/picsum/536/354" @{${blog.firstPicture}} alt="" class="ui fluid rounded image">
            </div>

            <!--article-->
            <div class="ui  attached padded segment">
                <!--标题区域-->
                <div class="ui right aligned basic segment">
                    <div class="ui orange basic label" th:text="${blog.flag}">转载</div>
                </div>

                <h2 class="ui center aligned header" th:text="${blog.title}">乐观锁和悲观锁</h2>

                <br>
                <!--内容区域-->
                <div id="content" class="typo typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large" th:utext="${blog.content}">


                </div>

                <!--标签-->
                <div class="m-padded-lr-responsive">
                    <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">多线程</div>
                </div>

                <!--赞赏-->
                <div th:if="${blog.appreciation}">
                    <div class="ui center aligned basic segment">
                        <button id="payButton" class="ui orange basic circular button">赞赏</button>
                    </div>
                    <div class="ui payQR flowing popup transition hidden">
                        <div class="ui orange basic label">
                            <div class="ui images">
                                <div class="image">
                                    <img src="../static/images/link.jfif" th:src="@{/images/link.jfif}" alt="" class="ui rounded bordered image" style="width: 120px">
                                </div>
                                <div class="image">
                                    <img src="../static/images/link.jfif" th:src="@{/images/link.jfif}" alt="" class="ui rounded bordered image" style="width: 120px">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

            <!--博客信息-->
            <div class="ui attached positive message" th:if="${blog.shareStatement}">
                <div class="ui middle aligned grid">
                    <div class="eleven wide column">
                        <ul class="list">
                            <li>作者：<span th:text="${blog.user.nickname}">JavaGuide</span></li>
                            <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">xxxx-xx-xx xx:xx</span> </li>
                            <li>版权声明：自由转载-非商用-非衍生-保持署名</li>
                            <li>公众号转载：请在文末添加作者公众号二维码</li>
                        </ul>
                    </div>
                    <div class="five wide column">
                        <img src="../static/images/link.jfif" th:src="@{/images/link.jfif}" alt="" class="ui right floated rounded bordered image" style="width: 110px">
                    </div>
                </div>
            </div>

            <!--留言区域-->
            <div  class="ui bottom attached segment" th:if="${blog.commentable}">
                <!--留言列表-->
                <div id="comment-container" class="ui teal segment">
                    <div th:fragment="commentList">
                        <div class="ui threaded comments" style="max-width:100%">
                            <h3 class="ui dividing header">Comments</h3>
                            <div class="comment" th:each="comment:${comments}">
                                <a class="avatar">
                                    <img src="https://picsum.photos/id/1010/5184/3456"
                                    th:src="@{${comment.avatar}}">
                                </a>
                                <div class="content">
                                    <a class="author" th:text="${comment.nickname}">Matt</a>
                                    <div class="metadata">
                                        <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                    </div>
                                    <div class="text" th:text="${comment.content}">
                                        How artistic!
                                    </div>
                                    <div class="actions">
                                        <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                           th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)">回复</a>
                                    </div>
                                </div>
                                <div class="comments" th:if="${#arrays.length(comment.replyComments)>0}">
                                    <div class="comment" th:each="reply:${comment.replyComments}">
                                        <a class="avatar">
                                            <img src="https://picsum.photos/id/1010/5184/3456"
                                                 th:src="@{${reply.avatar}}">
                                        </a>
                                        <div class="content">
                                            <a class="author" >
                                                <span th:text="${reply.nickname}">Matt</span>
                                                <span th:text="|@ ${reply.parentComment.nickname}|" class="m-teal">@</span>
                                            </a>
                                            <div class="metadata">
                                                <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                            </div>
                                            <div class="text" th:text="${reply.content}">
                                                How artistic!
                                            </div>
                                            <div class="actions">
                                                <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                                   th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)">回复</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!--/*-->
                            <div class="comment">
                                <a class="avatar">
                                    <img src="https://picsum.photos/id/1010/5184/3456">
                                </a>
                                <div class="content">
                                    <a class="author">Elliot Fu</a>
                                    <div class="metadata">
                                        <span class="date">Yesterday at 12:30AM</span>
                                    </div>
                                    <div class="text">
                                        <p>This has been very useful for my research. Thanks as well!</p>
                                    </div>
                                    <div class="actions">
                                        <a class="reply">回复</a>
                                    </div>
                                </div>
                                <div class="comments">
                                    <div class="comment">
                                        <a class="avatar">
                                            <img src="https://picsum.photos/id/1010/5184/3456">
                                        </a>
                                        <div class="content">
                                            <a class="author">Jenny Hess</a>
                                            <div class="metadata">
                                                <span class="date">Just now</span>
                                            </div>
                                            <div class="text">
                                                Elliot you are always so right :)
                                            </div>
                                            <div class="actions">
                                                <a class="reply">回复</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="comment">
                                <a class="avatar">
                                    <img src="https://picsum.photos/id/1010/5184/3456">
                                </a>
                                <div class="content">
                                    <a class="author">Joe Henderson</a>
                                    <div class="metadata">
                                        <span class="date">5 days ago</span>
                                    </div>
                                    <div class="text">
                                        Dude, this is awesome. Thanks so much
                                    </div>
                                    <div class="actions">
                                        <a class="reply">回复</a>
                                    </div>
                                </div>
                            </div>
                            <!--*/-->
                        </div>
                    </div>
                </div>

                <!--表单区域-->
                <div id="comment-form" class="ui form">
                    <input type="hidden" name="blog.id" th:value="${blog.id}">
                    <input type="hidden" name="parentComment.id" th:value="-1">

                    <div class="field">
                        <textarea name="content" id="" placeholder="请输入评论内容..."></textarea>
                    </div>
                    <div class="fields">
                        <div class="field m-mobile-wide m-margin-bottom-small">
                            <div class="ui left icon input m-mobile-wide">
                                <i class="user icon"></i>
                                <input type="text" name="nickname" placeholder="姓名">
                            </div>
                        </div>
                        <div class="field m-mobile-wide m-margin-bottom-small">
                            <div class="ui left icon input m-mobile-wide">
                                <i class="mail icon"></i>
                                <input type="text" name="email" placeholder="邮箱">
                            </div>
                        </div>
                        <div class="field m-mobile-wide m-margin-bottom-small">
                            <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="m-padded m-fixed m-right-bottom">
        <div class="ui vertical icon buttons ">
            <button type="button" class="ui toc button">目录</button>
            <a href="#comment-container" type="button" class="ui  button">留言</a>
            <button type="button" class="ui wechat icon button"><i class="weixin icon"></i></button>
            <div id="toTop-button" class="ui icon button"><i class="chevron up icon"></i></div>
        </div>
    </div>

    <!--目录-->
    <div class="ui toc-container flowing popup transition hidden" style="width: 250px">
        <ol class="js-toc">

        </ol>
    </div>

    <!--微信二维码-->
    <div id="qrcode" class="ui wechatQR flowing popup transition hidden " style="width: 130px">
<!--        <img src="./static/images/link.jfif" alt="" class="ui rounded image" style="width: 120px">-->
    </div>

<br>
<br>
<!--底部 footer-->
    <footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">

        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid">
                <div class="three wide column">
                    <ui class="ui inverted link list">
                        <div class="item">
                            <img src="../static/images/link.jfif"
                                 class="ui rounded image"
                                 style="width: 110px"
                                 alt="">
                        </div>
                    </ui>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">用户故事（User Story）</a>
                        <a href="#" class="item">用户故事（User Story）</a>
                        <a href="#" class="item">用户故事（User Story）</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">Email：contact@email.com</a>
                        <a href="#" class="item">QQ：123456</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">Blog</h4>
                    <p class="m-text-thin m-text-spaced m-opacity-mini">个人博客、分享关于编程、写作</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright @ 2020 - 2021 Su Designed by Su</p>
        </div>
    </footer>


<th:block th:replace="_fragments :: script">
    <!-- 引入jquery-->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>

    <!--引入semantic-ui框架-->
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>

    <!--平滑滚动-->
    <script src="https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.3/jquery.scrollTo.min.js"></script>

    <!--引入 自动生成目录 插件-->
    <script src="../static/lib/tocbot/tocbot.min.js"></script>

    <!--引入 中文排版 插件-->
    <script src="../static/lib/prism/prism.js"></script>

    <!--二维码生成 qrcode-->
    <script src="../static/lib/qrcode/qrcode.min.js"></script>
</th:block>


<script th:inline="javascript">
    $('.menu.toggle').click(function (){
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('#payButton').popup({
        popup: $('.payQR.popup'),
        on:'click',
        position:'bottom center'
    });

    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on:'click',
        position:'left center'
    });

    $('.wechat').popup({
        popup: $('.wechatQR'),
        position:'left center'
    });

    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
        // For headings inside relative or absolute positioned containers within content.
        hasInnerContainers: true,
    });


    var server = /*[[#{blog.serverUrl}]]*/"127.0.0.1:8080";
    var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
        text: server + url,
        width: 110,
        height: 110,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });

    $('#toTop-button').click(function (){
       $(window).scrollTo(0,500);
    });

    //评论表单验证
    $('.ui.form').form({
        fields:{
            title:{
                identifier:'content',
                rules:[{
                    type:'empty',
                    prompt:'请输入评论内容'
                }]
            },
            content:{
                identifier:'nickname',
                rules:[{
                    type:'empty',
                    prompt:'请输入昵称'
                }]
            },
            type:{
                identifier:'email',
                rules:[{
                    type:'email',
                    prompt:'请填写正确的邮箱地址'
                }]
            }
        }
    });
    
    $(function () {
        $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/);
    });

    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if(boo){
            postData();
        }else{
            console.log("校验失败");
        }
    });
    
    function postData() {
        $('#comment-container').load(/*[[@{/comments}]]*/"",{
            "parentComment.id":$("[name='parentComment.id']").val(),
            "blog.id":$("[name='blog.id']").val(),
            "nickname":$("[name='nickname']").val(),
            "email":$("[name='email']").val(),
            "content":$("[name='content']").val(),
        },function(responseTxt,statusTxt,xhr){
            $(window).scrollTo($('#comment-container'),500);
            clearContent();
        });
    }

    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder","请输入评论信息...");

    }

    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');

        $("[name='content']").attr("placeholder","@"+commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'),500);
    }
</script>
</body>
</html>